package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00101.MeetDay00101BannerBean;
import com.example.shixunandjavagotoyangchen.R;
import com.example.shixunandjavagotoyangchen.Sunshine.FragmentSpaek.FragmentSpaek2;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;


public class BlankFragmentDay00101 extends BasterFragment {


    List<MeetDay00101BannerBean.ValuesBean> valuesBeans;
    private Banner day00101Banner;
    private TabLayout day00101TabLayout;
    private ViewPager day00101ViewPager;

    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day00101;
    }

    @Override
    public void initView() {
        day00101Banner = (Banner) findViewById(R.id.day00101_banner);
        day00101TabLayout = (TabLayout) findViewById(R.id.day00101_TabLayout);
        day00101ViewPager = (ViewPager) findViewById(R.id.day00101_ViewPager);
    }

    @Override
    public void initDate() {

        //数据
        ArrayList<Fragment> day1fragment = new ArrayList<>();
        ArrayList<String> day1string = new ArrayList<>();

        day1fragment.add(new BlankFragmentDay00111());
        day1fragment.add(new BlankFragmentDay00122());
        day1fragment.add(new BlankFragmentDay00133());
        day1fragment.add(new BlankFragmentDay00144());
        day1fragment.add(new BlankFragmentDay00155());
        day1fragment.add(new BlankFragmentDay00166());
        day1fragment.add(new BlankFragmentDay00177());
        day1fragment.add(new BlankFragmentDay00188());

        day1string.add("推荐");
        day1string.add("球鞋");
        day1string.add("买家秀");
        day1string.add("特惠");
        day1string.add("男装");
        day1string.add("高街");
        day1string.add("女装");
        day1string.add("生活");

        FragmentSpaek2 list = new FragmentSpaek2(getActivity().getSupportFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, day1fragment, day1string);
        day00101ViewPager.setAdapter(list);
        day00101TabLayout.setupWithViewPager(day00101ViewPager);


        valuesBeans = new ArrayList<>();
        List<String> stringList = new ArrayList<>();
        OkGo.<String>get("http://10.161.52.10/yoho/Home_banner.php").execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                Gson gson = new Gson();
                MeetDay00101BannerBean bannerBean = gson.fromJson(response.body().toString(), MeetDay00101BannerBean.class);
                valuesBeans = bannerBean.getValues();//------全局
                day00101Banner.setImages(valuesBeans);//------设置图片
                for (MeetDay00101BannerBean.ValuesBean list : valuesBeans) {
                    stringList.add(list.getRecommend_name().toString());//------设置文字
                }
                day00101Banner.setBannerTitles(stringList);//------设置文字
                day00101Banner.setBannerAnimation(Transformer.RotateDown);//------设置动画效果
                day00101Banner.setBannerStyle(BannerConfig.NUM_INDICATOR_TITLE);//------类型
                day00101Banner.setImageLoader(new ImageLoader() {
                    @Override
                    public void displayImage(Context context, Object path, ImageView imageView) {
                        MeetDay00101BannerBean.ValuesBean dataBean = (MeetDay00101BannerBean.ValuesBean) path;
                        Glide.with(getActivity()).load("http://10.161.14.97/yoho/" + dataBean.getRecommend_url()).into(imageView);//------设置解析图片
                    }
                }).start();
            }
        });


    }
}
